#ifndef COMPASS_H_
#define COMPASS_H_

/****************************************************************
*						PAXS ELECTRONICS						*
* 																*
*																*
* - Compiler:           Code Composer Studio (Licensed)			*
* - Supported devices:  All Stellaris Family Cortex-M3.			*
* - AppNote:													*
*																*
* \author               Juan Francisco Gomez 					*
* \Contac				pacoduz@gmail.com					2011*
*****************************************************************
*
* File/
*  Tilt Compensated Compass Function.
*  Provide a Heading parallel to the surface of the earth.
*  Compass always points Magnetic North. Additionally, 
*  Magnetic Deviation on your current position, can be 
*  obtained from this website: http://magnetic-declination.com/ 
*  this info can be converted to Radians in this web site:
*  http://www.wolframalpha.com/input/?i=%284%C2%B0+21%27%29+in+radians
*  
*	This code uses a fixed-point library to do all Math. 
*   The IQMath Library provided by Texas Instruments to 
*   be used on Stellaris and C2000 Microcontrollers families.
* 
*   Code adapted to be used with 9DOFSensor Stick From SparkFun.
*   Due to My 9DOF Sensor Stick Orientation, magnetic Axis signs 
*   are inverted (only X and Y Axes). All this can be seen in 
*   Compass.c **IMPORTAN: Don't modify 
* 
* 	THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
*	NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
*	NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
*	A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
*   Juan Francisco Gomez SHALL NOT, UNDER ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, 
*   INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
* 
*/
	
	#include "lm3s5749.h"
	#include "Imu9DOFDriver.h"
	#include "Dcm.h"
	#define   GLOBAL_Q	16
	#include "IQmath/IQmathLib.h"
	
	//////////////////////////////
	//	 	9DOF SENSOR			//		
	//////////////////////////////
	#define SEN_10724		0			//HMC5883L
	#define SEN_10321		1			//HMC5834
	#define SENSOR			(SEN_10724)
	
	//////////////////////////////////////////
	//	IMU ORIENTATION  CONFIGURATION  	//
	//////////////////////////////////////////
	#define FIRST_ORIENTATION			0
	#define SECOND_ORIENTATION			1
	#define IMU							(FIRST_ORIENTATION)
	// **IMPORTANT** Must be define same configuration in Compass.h and Dcm.h
	// Orientation description at DCM.h
	
	//////////////////////////////////////////////////////
	//		EXTERNAL VARIABLES AS COMPASS OUTPUTs		//
	//////////////////////////////////////////////////////
	//MagneticHeading in Radians
	extern _iq MagneticHeading;					
	
	//////////////////////////////////////////
	//		PROTOTYPE EXTERNAL FUNCTION		//
	//////////////////////////////////////////
	/*
	 * void CompassHeading (_iq roll,_iq pitch);
	 * Function to calculate tilt-compensated Heading
	 * for this Roll and Pitch angles must be introduced
	 * to the function.
	 * Ptich and Roll Angles inputs must be Radians 
	 */
	void CompassHeading (_iq roll,_iq pitch);	
	
#endif /*COMPASS_H_*/
